package cn.bellychang.leetcode.question252;

import java.util.HashSet;

/**
 *
 * given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei),
 * determine if a person could attend all meetings.
 *
 * Example 1:
 *
 * Input: [[0,30],[5,10],[15,20]]
 * Output: false
 *
 *
 * Example 2:
 *
 * Input: [[7,10],[2,4]]
 * Output: true
 *
 *
 * @author ChangLiang
 * @date 2021/3/22
 */
public class Solution {

    public boolean canAttendMeetings(int[][] intervals) {

        // 看两个数组是否相交

        HashSet<Integer> hashSet = new HashSet<>();
        for (int i = 0; i < intervals.length; i++) {
            int[] interval = intervals[i];
            for (int j = interval[0]; j <= interval[1]; j++) {
                if (hashSet.contains(j)) {
                    return false;
                } else {
                    hashSet.add(j);
                }
            }
        }
        return true;
    }
}
